﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Aribaccio;
using BDPAutodetect.Mgrcore;
using BDPAutodetect.Models;
using CommunityToolkit.Mvvm.ComponentModel;

namespace BDPAutodetect.Client
{
    /// <summary>
    /// 窗体视图模型
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public partial class BaseViewModel<T> : ObservableModel where T : class
    {
        /// <summary>
        /// 线程同步更新View
        /// </summary>
        protected readonly TaskScheduler syncContextTask = TaskScheduler.FromCurrentSynchronizationContext();
        /// <summary>
        /// 版本显示
        /// </summary>
        [ObservableProperty]
        protected string versionDisplay = $"V{Assembly.GetExecutingAssembly().GetName().Version}";
        /// <summary>
        /// 是否有编辑权限
        /// </summary>
        [ObservableProperty]
        protected Visibility isVisibilityPermission = Visibility.Hidden;
        /// <summary>
        /// 是否已在执行完成[用于Command命令中]
        /// </summary>
        [ObservableProperty]
        protected bool isExecutedIdle = true;
        /// <summary>
        /// 是已经初始化加载
        /// </summary>
        [ObservableProperty]
        protected bool isLoaded = false;

        /// <summary>
        /// 窗体对象
        /// </summary>
        public T? Parent { get; set; }
        /// <summary>
        /// 权限许可
        /// </summary>
        public MPowerPermission? PowerPermission { get; protected set; }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public BaseViewModel()
        {

        }

        /// <summary>
        /// 带出构造函数
        /// </summary>
        /// <param name="argParent"></param>
        public BaseViewModel(T argParent)
        {
            this.Parent = argParent;
        }

        /// <summary>
        /// 注册窗体对象
        /// </summary>
        public virtual void RegisterParent(T argParent) { this.Parent = argParent; }

        /// <summary>
        /// 传输变更数据
        /// </summary>
        /// <typeparam name="TData">泛型</typeparam>
        /// <param name="argData">传递数据</param>
        public virtual void TransferChangeData<TData>(TData argData) where TData : class, new()
        {

        }

        /// <summary>
        /// 传输权限许可信息
        /// </summary>
        public virtual void TransferPowerPermission(MPowerPermission argPowerPermission)
        {
            this.PowerPermission = argPowerPermission;
        }
    }
}
